import { FormSchema } from '/@/components/Form'
import { BasicColumn } from '/@/components/Table'
import { h } from 'vue'

export const columns = (): BasicColumn[] => {
  return [
    {
      title: '序号',
      dataIndex: 'index',
      key: 'index',
      align: 'center',
      width: 80,
      fixed: true,
    },
    {
      title: '考生姓名',
      dataIndex: 'xm',
      key: 'xm',
      align: 'center',
      width: 150,
      ellipsis: true,
    },

    {
      title: '考生准考证号',
      dataIndex: 'zkzh',
      key: 'zkzh',
      align: 'center',
      width: 150,
      ellipsis: true,
    },
    {
      title: '学院名称',
      dataIndex: 'xymc',
      key: 'xymc',
      align: 'center',
      customRender: ({ record }: any) => {
        return `${record.xydm}(${record.xymc || '--'})`
      },
      width: 150,
      ellipsis: true,
    },
    {
      title: '科目名称',
      dataIndex: 'kmdm',
      key: 'kmdm',
      align: 'center',
      customRender: ({ record }: any) => {
        return `${record.kmdm}(${record.kmmc})`
      },
      width: 200,
      ellipsis: true,
    },
    {
      title: '客观题归档成绩',
      dataIndex: 'kgf',
      key: 'kgf',
      align: 'center',
      width: 200,
      ellipsis: true,
    },
    {
      title: '主观题归档成绩',
      dataIndex: 'zgf',
      key: 'zgf',
      align: 'center',
      width: 200,
      ellipsis: true,
    },
    {
      title: '归档成绩',
      dataIndex: 'zgt',
      key: 'zgt',
      align: 'center',
      width: 200,
      ellipsis: true,
      customRender: ({ record }: any) => {
        return Math.round(Number(record.kgf || 0) + Number(record.zgf || 0))
      },
    },
    {
      title: '册号',
      dataIndex: 'ch',
      key: 'ch',
      align: 'center',
      width: 150,
      ellipsis: true,
    },
    {
      title: '册内序号',
      dataIndex: 'cnxh',
      key: 'cnxh',
      align: 'center',
      width: 150,
      ellipsis: true,
    },
    {
      title: '扫描状态',
      dataIndex: 'sfsm',
      key: 'sfsm',
      align: 'center',
      width: 80,
      customRender: ({ text }) => {
        return h(
          'span',
          {
            class: text === 1 ? 'text-green-600 ' : 'text-red-600',
            title: text === 1 ? '已扫描' : text === 0 ? '未扫描' : '--',
          },
          text === 1 ? '已扫描' : text === 0 ? '未扫描' : '--'
        )
      },
      ellipsis: true,
    },

    {
      title: '操作',
      dataIndex: 'operation',
      align: 'center',
      width: 150,
      fixed: 'right',
    },
  ]
}

export const columnsImport = () => {
  return [
    {
      title: '文件名',
      dataIndex: 'wjmc',
    },
    {
      title: '导入成功数',
      dataIndex: 'cgts',
    },
    {
      title: '导入失败数',
      dataIndex: 'sbts',
    },
    {
      title: '总条数',
      dataIndex: 'zts',
    },
    {
      title: '导入时间',
      dataIndex: 'createTime',
    },
  ]
}

export const formSchemas = (): FormSchema[] => {
  return [
    {
      field: 'kmdm',
      label: '科目代码',
      colProps: { span: 6 },
      component: 'Input',
      rulesMessageJoinLabel: true,
    },
    {
      field: 'ksbh',
      label: '考生编号',
      colProps: { span: 6 },
      component: 'Input',
      rulesMessageJoinLabel: true,
    },
    {
      field: 'xm',
      label: '考生姓名',
      colProps: { span: 6 },
      component: 'Input',
      rulesMessageJoinLabel: true,
    },
    {
      field: 'sfcl',
      label: '是否证实',
      colProps: { span: 6 },
      component: 'Select',
      defaultValue: 'n',
      rulesMessageJoinLabel: true,
      componentProps: function () {
        return {
          options: [
            { label: '是', value: 'y' },
            { label: '否', value: 'n' },
          ],
        }
      },
    },
    {
      field: 'sfyc',
      label: '是否异常',
      colProps: { span: 6 },
      component: 'Select',
      rulesMessageJoinLabel: true,
      componentProps: function () {
        return {
          options: [
            { label: '是', value: 'y' },
            { label: '否', value: 'n' },
          ],
        }
      },
    },
  ]
}

export const formSchemasImport = (): FormSchema[] => {
  return [
    {
      field: 'wjmc',
      label: '文件名称',
      colProps: { span: 6 },
      component: 'Input',
      rulesMessageJoinLabel: true,
    },
  ]
}

export const columnsLine = (activeKey: string): BasicColumn[] => {
  if (activeKey === 'success') {
    return [
      {
        title: '年份',
        dataIndex: 'nf',
      },
      {
        title: '考生编号',
        dataIndex: 'ksbh',
      },
      {
        title: '考生姓名',
        dataIndex: 'xm',
      },
      {
        title: '科目代码',
        dataIndex: 'kmdm',
      },
      {
        title: '科目名称',
        dataIndex: 'kmmc',
      },
      {
        title: '考试分数',
        dataIndex: 'ksfs',
      },
      {
        title: '查分理由',
        dataIndex: 'cfly',
      },
    ]
  } else {
    return [
      {
        title: '年份',
        dataIndex: 'nf',
      },
      {
        title: '考生编号',
        dataIndex: 'ksbh',
      },
      {
        title: '考生姓名',
        dataIndex: 'xm',
      },
      {
        title: '科目代码',
        dataIndex: 'kmdm',
      },
      {
        title: '科目名称',
        dataIndex: 'kmmc',
      },
      {
        title: '考试分数',
        dataIndex: 'ksfs',
      },
      {
        title: '查分理由',
        dataIndex: 'cfly',
      },
      {
        title: '失败原因',
        dataIndex: 'sbyy',
      },
    ]
  }
}

//搜索条件
export const formSchemasLine = (): FormSchema[] => {
  return [
    {
      field: 'kmdm',
      label: '科目代码',
      colProps: { span: 6 },
      component: 'Input',
      rulesMessageJoinLabel: true,
    },
    {
      field: 'ksbh',
      label: '考生编号',
      colProps: { span: 6 },
      component: 'Input',
      rulesMessageJoinLabel: true,
    },
    {
      field: 'xm',
      label: '考生姓名',
      colProps: { span: 6 },
      component: 'Input',
      rulesMessageJoinLabel: true,
    },
  ]
}

export function modalFormItem(activeKey: string): FormSchema[] {
  if (activeKey === 'success') {
    return [
      {
        field: 'remark',
        label: '备注',
        component: 'ShowSpan',
        colProps: { span: 12 },
      },
    ]
  } else {
    return [
      {
        field: 'remark',
        label: '备注',
        component: 'InputTextArea',
        colProps: { span: 24 },
      },
    ]
  }
}
